package com.ktjy.t382.ch01.service.impl;

import com.ktjy.t382.ch01.mapper.BookManageMapper;
import com.ktjy.t382.ch01.pojo.BookManage;
import com.ktjy.t382.ch01.pojo.Page;
import com.ktjy.t382.ch01.service.BookManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookManageServiceImp implements BookManageService {

    @Autowired
    private BookManageMapper bookManageMapper;

    @Override
    public List<BookManage> getListBiz(BookManage bookManage) {
        return bookManageMapper.getList(bookManage);
    }

    @Override
    public BookManage getByIdBiz(Integer id) {
        return bookManageMapper.getById(id);
    }

    @Override
    public int insertBiz(BookManage bookManage) {
        return bookManageMapper.insert(bookManage);
    }

    @Override
    public int updateBiz(BookManage bookManage) {
        return bookManageMapper.update(bookManage);
    }

    @Override
    public int deleteBiz(Integer id) {
        return bookManageMapper.delete(id);
    }

    @Override
    public Page getPage(Integer pageNo, Integer pageSize, String b_name) {
        Page page = new Page();
        try {
            page.setPageNo(pageNo);//当前页
            page.setPageSize(pageSize);//每页显示的数据量
            Long total = bookManageMapper.count();//总记录数
            page.setTotalCount(total.intValue());
            int offset = (pageNo - 1) * pageSize;// 计算偏移量
            List<BookManage> list = bookManageMapper.getPage(offset, pageSize, b_name);
            page.setList(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return page;
    }

    @Override
    public Long count() {
        return bookManageMapper.count();
    }
}
